import request from '@/utils/request';
import { AllTrademark, HasSaleAttrResponseData, SaleAttrResponseData, SpuData, SpuHasImage, SpuResponseData } from './types';
// 统一接口管理
enum API {
  GET_SPU_URL = '/admin/product', // 获取已有的SPU数据
  GET_ALL_TRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList', // 获取全部品牌的数据
  GET_SPU_IMAGE_URL = '/admin/product/spuImageList', // 获取某个spu下的全部售卖商品的图片数据
  GET_SPU_SALEATTR_URL = '/admin/product/spuSaleAttrList', // 获取某个spu的销售属性列表
  GET_ALL_SALEATTR_URL = '/admin/product/baseSaleAttrList', // 获取整个项目全部的销售属性列表

  ADD_SPU_URL = '/admin/product/saveSpuInfo', // 添加SPU
  UPDATE_SPU_URL = '/admin/product/updateSpuInfo', // 修改SPU
  DELETE_SPU_URL = '/admin/product/deleteSpu', // 删除SPU
  View_SPU_URL = '/admin/product/getSpuInfo', // 查看SKU
}

// 获取已有的SPU数据
export const reqGetSPU = (page: number, limit: number, category3Id?: number | string) => {
  return request.get<any, SpuResponseData>(API.GET_SPU_URL + `/${page}/${limit}?category3Id=${category3Id}`);
};
// 获取全部品牌的数据
export const reqGetAllTrademark = () => {
  return request.get<any, AllTrademark>(API.GET_ALL_TRADEMARK_URL);
};
// 获取某个spu下的全部售卖商品的图片数据
export const reqGetSpuImageList = (spuId: number) => {
  return request.get<any, SpuHasImage>(API.GET_SPU_IMAGE_URL + `/${spuId}`);
};
// 获取某个spu的销售属性列表
export const reqGetSpuSaleAttrList = (spuId: number) => {
  return request.get<any, SaleAttrResponseData>(API.GET_SPU_SALEATTR_URL + `/${spuId}`);
};
// 获取整个项目全部的销售属性列表
export const reqGetSaleAttrList = () => {
  return request.get<any, HasSaleAttrResponseData>(API.GET_ALL_SALEATTR_URL);
};

// 添加SPU或者修改SPU
export const reqAddOrUpdateSPU = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATE_SPU_URL, data);
  } else {
    return request.post<any, any>(API.ADD_SPU_URL, data);
  }
};
// 删除SPU
export const reqDeleteSPU = (spuId: number) => {
  return request.delete<any, any>(API.DELETE_SPU_URL + `/${spuId}`);
};
// 查看SKU
export const reqViewSPU = (spuId: number) => {
  return request.get<any, any>(API.View_SPU_URL + `/${spuId}`);
};
